package com.aiti.lulian.controller;

import cn.hutool.core.util.StrUtil;
import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.service.ILuLianDockingMeetingDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author WongMZ
 * @CreateDate 2024-05-28
 * @Description: LuLianDockingMeetingDetails控制类
 */
@RestController
@RequestMapping("/meeting")
@Api(tags = "luLianDockingMeetingDetails", description = "luLianDockingMeetingDetails")
public class LuLianDockingMeetingDetailsController extends WebController {
    protected final Logger logger = LoggerFactory.getLogger(LuLianDockingMeetingDetailsController.class);
    @Autowired
    private ILuLianDockingMeetingDetailsService detailsService;

    @ApiOperation(value = "根据baseId查询供需对接会详情")
    @GetMapping("/{baseId}")
    public Message getDetailsByBaseId(@PathVariable("baseId") String baseId) {
        try {
            if (StrUtil.isEmpty(baseId)) {
                logger.error("查询异常：===》入参异常");
                return Error("入参异常");
            }
            return Success(detailsService.getDetailsByBaseId(baseId));
        } catch (Exception e) {
            logger.error("查询异常：===》" + e);
            return Error(e.getMessage());
        }
    }

    @ApiOperation(value = "查询供需对接会列表-分页")
    @GetMapping
    public Message getDetailsListPage(@RequestParam("pageNum") String pageNum,
                                      @RequestParam("pageSize") String pageSize,
                                      @RequestParam(value = "keyword",required = false) String keyword,
                                      @RequestParam(value = "meetingStatus", required = false) String meetingStatus,
                                      @RequestParam(value = "xcVideo", required = false) String xcVideo,
                                      @RequestParam(value = "govFlag", required = false) String govFlag,
                                      @RequestParam(value = "city", required = false) String city,
                                      @RequestParam(value = "county", required = false) String county) {
        try {
            if (StrUtil.isEmpty(pageNum) || StrUtil.isEmpty(pageSize)) {
                logger.error("查询异常：===》入参异常");
                return Error("入参异常");
            }
            return Success(detailsService.getDetailsListPage(Integer.valueOf(pageNum), Integer.valueOf(pageSize), meetingStatus, xcVideo,keyword, govFlag, city, county));
        } catch (Exception e) {
            logger.error("查询异常：===》" + e);
            return Error(e.getMessage());
        }
    }

    /**
     * 查询会议报名情况
     * @return
     */
    @GetMapping("/queryMeetingEnroll")
    public Message queryMeetingEnroll(){
        String userId = findUserId();
        List<Map<String, Object>> maps = detailsService.queryMeetingEnroll(userId);
        return Message.success(maps);
    }
}